import 'dart:math';

import 'package:flutter/material.dart';

import 'MConstant.dart';

/*
网络篇

Http网络操作
 */
class HttpDemo extends StatefulWidget {
  @override
  _FunctionDemo createState() => new _FunctionDemo();
}

class _FunctionDemo extends State<HttpDemo> {
  /*
   * 创建路由集合集合
   * Key为路由路径
   * value为文本
   */
  var routesMap = MConstant.getHttpRoutesName();

  var colorList = [
    Colors.greenAccent,
    Colors.green,
    Colors.blue,
    Colors.red,
    Colors.amber,
    Colors.black54,
    Colors.deepPurple,
    Colors.pink
  ];
  var random = new Random();

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemBuilder: (context, index) {
        return Padding(
          padding: EdgeInsets.fromLTRB(12.0, 0, 12.0, 0),
          child: RaisedButton(
            onPressed: () {
              Navigator.pushNamed(
                context, routesMap.keys.toList()[index]);
            },
            child: Text(routesMap.values.toList()[index],
              style: TextStyle(color: Colors.white, fontSize: 14.0)),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(25)),
            elevation: 2.0,
            highlightElevation: 8.0,
            disabledElevation: 0.0,
            color: colorList[random.nextInt(colorList.length)],
          ),
        );
      },
      itemCount: routesMap.length);
  }
}
